package barricades;
import java.awt.Graphics;
import java.awt.Point;

//default staerke ist 4 fuer die barricaden

public abstract class Barricade {

	public int x_start;
	public int x_end;
	public int y_start;
	public int y_end;
	
	//public static enum TYPE {HORIZONTAL, VERTICAL, DIAGONAL_LEFT_BOTTOM,DIAGONAL_LEFT_TOP};
	protected final int DEF_SIZE=4;
	
	/*
	 * constructors
	 */
	public Barricade(){};
	
	public Barricade(Point s, Point e){
		x_start=s.x;
		x_end=e.x;
		y_start=s.y;
		y_end=e.y;
	}
	
	public Barricade(Barricade b){
		 x_start=b.x_start;
		 x_end=b.x_end;
		 y_start=b.y_start;
		 y_end=b.y_end;
	}
	

	
	/*
	 * cuts the ends of a barricade if it is out of the simulation bounds
	 */
	public void setInBounds(int w, int h){
			
		if(x_start<0)
			x_start=0;
		
		if(y_start<0)
			y_start=0;
		
		if(x_end>w)
			x_end=w;
		
		 if(y_end>h)
			y_end=h;
	}
	
		
	protected void loopHelper(int comparable,boolean start,boolean down,boolean x){
		int k=y_start;
		for(int j=x_start;j<=x_end;j++){
			//wann wird gleichgesetzt
			
			if((!x&&k==comparable) ||(x&&j==comparable)){
				//was wird gleichgesetzt
				if(start){
					x_start=j;
					y_start=k;
				}else{
					x_end=j;
					y_end=k;
				}
				break;
			}
			//welcher diagonalzweig wurde genommen
			if (down)
				k--;
			else
				k++;
		}
	}
	
	public void setNewStartPosition(Point s){
		x_start=s.x;
		y_start=s.y;
	}
	
	public void setNewEndPosition(Point e){
		x_end=e.x;
		y_end=e.y;
	}
	
	public void setPosition(Point s,Point e){
		x_start=s.x;
		y_start=s.y;
		x_end=e.x;
		y_end=e.y;
	}
	
	public void drawPosition(Graphics g){
		g.drawLine(x_start, y_start, x_end,y_end);
	}
	
	public String toString(){
		return "("+x_start+","+y_start+") - ("+x_end+","+y_end+") ";
	}
}//class Barricade
 